if we move to the front of a segment, use the "slow" technique for moving
authorHavoc Pennington <hp@pobox.com>
Wed, 24 Oct 2001 04:48:21 +0000 (04:48 +0000)
committerHavoc Pennington <hp@src.gnome.org>
Wed, 24 Oct 2001 04:48:21 +0000 (04:48 +0000)
2001-10-24  Havoc Pennington  <hp@pobox.com>

* gtk/gtktextiter.c (gtk_text_iter_backward_chars): if we move to
the front of a segment, use the "slow" technique for moving
backward, so we don't mess up the any_segment field in the iter.
Fixes #57707

* tests/testtextbuffer.c: add code to detect #57707, to avoid
regression

ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
docs/reference/gtk/tmpl/gtkmenu.sgml
gtk/gtktextiter.c
tests/testtextbuffer.c

index 7806eeffb91230097e9b98f016ee9f0b40028b10..b6e5c1a51c39ddc67dd0b25bfeb3096ed17e64ca 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2001-10-24  Havoc Pennington  <hp@pobox.com>
+
+       * gtk/gtktextiter.c (gtk_text_iter_backward_chars): if we move to
+       the front of a segment, use the "slow" technique for moving
+       backward, so we don't mess up the any_segment field in the iter. 
+       Fixes #57707
+
+       * tests/testtextbuffer.c: add code to detect #57707, to avoid
+       regression
+
 2001-10-23  Havoc Pennington  <hp@redhat.com>
 
        * gtk/gtktextview.c (popup_targets_received): only sensitize Cut
index 7806eeffb91230097e9b98f016ee9f0b40028b10..b6e5c1a51c39ddc67dd0b25bfeb3096ed17e64ca 100644 (file)
@@ -1,3 +1,13 @@
+2001-10-24  Havoc Pennington  <hp@pobox.com>
+
+       * gtk/gtktextiter.c (gtk_text_iter_backward_chars): if we move to
+       the front of a segment, use the "slow" technique for moving
+       backward, so we don't mess up the any_segment field in the iter. 
+       Fixes #57707
+
+       * tests/testtextbuffer.c: add code to detect #57707, to avoid
+       regression
+
 2001-10-23  Havoc Pennington  <hp@redhat.com>
 
        * gtk/gtktextview.c (popup_targets_received): only sensitize Cut
index 7806eeffb91230097e9b98f016ee9f0b40028b10..b6e5c1a51c39ddc67dd0b25bfeb3096ed17e64ca 100644 (file)
@@ -1,3 +1,13 @@
+2001-10-24  Havoc Pennington  <hp@pobox.com>
+
+       * gtk/gtktextiter.c (gtk_text_iter_backward_chars): if we move to
+       the front of a segment, use the "slow" technique for moving
+       backward, so we don't mess up the any_segment field in the iter. 
+       Fixes #57707
+
+       * tests/testtextbuffer.c: add code to detect #57707, to avoid
+       regression
+
 2001-10-23  Havoc Pennington  <hp@redhat.com>
 
        * gtk/gtktextview.c (popup_targets_received): only sensitize Cut
index 7806eeffb91230097e9b98f016ee9f0b40028b10..b6e5c1a51c39ddc67dd0b25bfeb3096ed17e64ca 100644 (file)
@@ -1,3 +1,13 @@
+2001-10-24  Havoc Pennington  <hp@pobox.com>
+
+       * gtk/gtktextiter.c (gtk_text_iter_backward_chars): if we move to
+       the front of a segment, use the "slow" technique for moving
+       backward, so we don't mess up the any_segment field in the iter. 
+       Fixes #57707
+
+       * tests/testtextbuffer.c: add code to detect #57707, to avoid
+       regression
+
 2001-10-23  Havoc Pennington  <hp@redhat.com>
 
        * gtk/gtktextview.c (popup_targets_received): only sensitize Cut
index 7806eeffb91230097e9b98f016ee9f0b40028b10..b6e5c1a51c39ddc67dd0b25bfeb3096ed17e64ca 100644 (file)
@@ -1,3 +1,13 @@
+2001-10-24  Havoc Pennington  <hp@pobox.com>
+
+       * gtk/gtktextiter.c (gtk_text_iter_backward_chars): if we move to
+       the front of a segment, use the "slow" technique for moving
+       backward, so we don't mess up the any_segment field in the iter. 
+       Fixes #57707
+
+       * tests/testtextbuffer.c: add code to detect #57707, to avoid
+       regression
+
 2001-10-23  Havoc Pennington  <hp@redhat.com>
 
        * gtk/gtktextview.c (popup_targets_received): only sensitize Cut
index 7806eeffb91230097e9b98f016ee9f0b40028b10..b6e5c1a51c39ddc67dd0b25bfeb3096ed17e64ca 100644 (file)
@@ -1,3 +1,13 @@
+2001-10-24  Havoc Pennington  <hp@pobox.com>
+
+       * gtk/gtktextiter.c (gtk_text_iter_backward_chars): if we move to
+       the front of a segment, use the "slow" technique for moving
+       backward, so we don't mess up the any_segment field in the iter. 
+       Fixes #57707
+
+       * tests/testtextbuffer.c: add code to detect #57707, to avoid
+       regression
+
 2001-10-23  Havoc Pennington  <hp@redhat.com>
 
        * gtk/gtktextview.c (popup_targets_received): only sensitize Cut
index 7806eeffb91230097e9b98f016ee9f0b40028b10..b6e5c1a51c39ddc67dd0b25bfeb3096ed17e64ca 100644 (file)
@@ -1,3 +1,13 @@
+2001-10-24  Havoc Pennington  <hp@pobox.com>
+
+       * gtk/gtktextiter.c (gtk_text_iter_backward_chars): if we move to
+       the front of a segment, use the "slow" technique for moving
+       backward, so we don't mess up the any_segment field in the iter. 
+       Fixes #57707
+
+       * tests/testtextbuffer.c: add code to detect #57707, to avoid
+       regression
+
 2001-10-23  Havoc Pennington  <hp@redhat.com>
 
        * gtk/gtktextview.c (popup_targets_received): only sensitize Cut
index b51c366a4b8e9cfdb935d43b88694d40851c99fa..b8f6c879354f39e68fa2b852deeb6fbb9f7d7dc5 100644 (file)
@@ -96,9 +96,9 @@ Creates a new #GtkMenu.
 Adds a new #GtkMenuItem to the end of the menu's item list.
 </para>
 
-<!-- # Unused Parameters # -->
 @menu: a #GtkMenu.
 @child: The #GtkMenuItem to add.
+<!-- # Unused Parameters # -->
 @m: 
 @c: 
 
@@ -108,9 +108,9 @@ Adds a new #GtkMenuItem to the end of the menu's item list.
 Adds a new #GtkMenuItem to the beginning of the menu's item list.
 </para>
 
-<!-- # Unused Parameters # -->
 @menu: a #GtkMenu.
 @child: The #GtkMenuItem to add.
+<!-- # Unused Parameters # -->
 @menu_child: 
 @m: 
 @c: 
@@ -122,10 +122,10 @@ Adds a new #GtkMenuItem to the menu's item list at the position
 indicated by @position. 
 </para>
 
-<!-- # Unused Parameters # -->
 @menu: a #GtkMenu.
 @child: The #GtkMenuItem to add.
 @pos: 
+<!-- # Unused Parameters # -->
 @position: The position in the item list where @child is added.
 Positions are numbered from 0 to n-1.
 
index 42e5678ee73a8d4d645166a6a4751a76c021c382..3f497d11103e15b0879ecdf88020f9d373d17f06 100644 (file)
@@ -2347,7 +2347,11 @@ gtk_text_iter_backward_chars (GtkTextIter *iter, gint count)
   ensure_char_offsets (real);
   check_invariants (iter);
 
-  if (count <= real->segment_char_offset)
+  /* <, not <=, because if count == segment_char_offset
+   * we're going to the front of the segment and the any_segment
+   * might change
+   */
+  if (count < real->segment_char_offset)
     {
       /* Optimize the within-segment case */
       g_assert (real->segment->char_count > 0);
@@ -2402,6 +2406,7 @@ gtk_text_iter_backward_chars (GtkTextIter *iter, gint count)
           new_char_index = current_char_index - count;
           if (new_char_index < 0)
             new_char_index = 0;
+
           gtk_text_iter_set_offset (iter, new_char_index);
 
           check_invariants (iter);
index f0dcd36f2dc0f8e7015a9027113d232a3af1ceb6..61837c96f394c6dbed5bde71cef364770cf72cd1 100644 (file)
@@ -92,10 +92,10 @@ main (int argc, char** argv)
   /* Put stuff in the buffer */
 
   fill_buffer (buffer);
-
+#if 0
   /* Subject stuff-bloated buffer to further torment */
   run_tests (buffer);
-
+#endif
   /* Delete all stuff from the buffer */
   gtk_text_buffer_get_bounds (buffer, &start, &end);
   gtk_text_buffer_delete (buffer, &start, &end);
@@ -112,6 +112,13 @@ main (int argc, char** argv)
 
   run_tests (buffer);
 
+  gtk_text_buffer_set_text (buffer, "adcdef", -1);
+  gtk_text_buffer_get_iter_at_offset (buffer, &start, 1);
+  gtk_text_buffer_get_iter_at_offset (buffer, &end, 3);
+  gtk_text_buffer_apply_tag_by_name (buffer, "fg_blue", &start, &end);
+  
+  run_tests (buffer);
+  
   g_object_unref (G_OBJECT (buffer));
   
   g_print ("All tests passed.\n");
@@ -203,32 +210,48 @@ count_toggles_at_iter (GtkTextIter *iter,
 
   return count;
 }
-     
+
 static gint
-count_toggles_in_buffer (GtkTextBuffer *buffer,
-                         GtkTextTag    *of_tag)
+count_toggles_in_range_by_char (GtkTextBuffer     *buffer,
+                                GtkTextTag        *of_tag,
+                                const GtkTextIter *start,
+                                const GtkTextIter *end)
 {
   GtkTextIter iter;
   gint count = 0;
   
-  gtk_text_buffer_get_iter_at_offset (buffer, &iter, 0);
+  iter = *start;
   do
     {
       count += count_toggles_at_iter (&iter, of_tag);
+      if (!gtk_text_iter_forward_char (&iter))
+        {
+          /* end iterator */
+          count += count_toggles_at_iter (&iter, of_tag);
+          break;
+        }
     }
-  while (gtk_text_iter_forward_char (&iter));
-
-  /* Do the end iterator, because forward_char won't return TRUE
-   * on it.
-   */
-  count += count_toggles_at_iter (&iter, of_tag);
+  while (gtk_text_iter_compare (&iter, end) <= 0);
   
   return count;
 }
 
+static gint
+count_toggles_in_buffer (GtkTextBuffer *buffer,
+                         GtkTextTag    *of_tag)
+{
+  GtkTextIter start, end;
+
+  gtk_text_buffer_get_bounds (buffer, &start, &end);
+
+  return count_toggles_in_range_by_char (buffer, of_tag, &start, &end);
+}
+
 static void
-check_specific_tag (GtkTextBuffer *buffer,
-                    const gchar   *tag_name)
+check_specific_tag_in_range (GtkTextBuffer     *buffer,
+                             const gchar       *tag_name,
+                             const GtkTextIter *start,
+                             const GtkTextIter *end)
 {
   GtkTextIter iter;
   GtkTextTag *tag;
@@ -236,17 +259,23 @@ check_specific_tag (GtkTextBuffer *buffer,
   gint count;
   gint buffer_count;
   gint last_offset;
+
+  if (gtk_text_iter_compare (start, end) > 0)
+    {
+      g_print ("  (inverted range for checking tags, skipping)\n");
+      return;
+    }
   
   tag = gtk_text_tag_table_lookup (gtk_text_buffer_get_tag_table (buffer),
                                    tag_name);
 
-  buffer_count = count_toggles_in_buffer (buffer, tag);
+  buffer_count = count_toggles_in_range_by_char (buffer, tag, start, end);
   
   state = FALSE;
   count = 0;
 
   last_offset = -1;
-  gtk_text_buffer_get_iter_at_offset (buffer, &iter, 0);
+  iter = *start;
   if (gtk_text_iter_toggles_tag (&iter, tag) ||
       gtk_text_iter_forward_to_tag_toggle (&iter, tag))
     {
@@ -278,17 +307,18 @@ check_specific_tag (GtkTextBuffer *buffer,
           else
             g_error ("forward_to_tag_toggle went to a location without a toggle");
         }
-      while (gtk_text_iter_forward_to_tag_toggle (&iter, tag));
+      while (gtk_text_iter_forward_to_tag_toggle (&iter, tag) &&
+             gtk_text_iter_compare (&iter, end) <= 0);
     }
 
   if (count != buffer_count)
-    g_error ("Counted %d tags iterating by char, %d iterating by tag toggle\n",
+    g_error ("Counted %d tags iterating by char, %d iterating forward by tag toggle\n",
              buffer_count, count);
   
   state = FALSE;
   count = 0;
   
-  gtk_text_buffer_get_end_iter (buffer, &iter);
+  iter = *end;
   last_offset = gtk_text_iter_get_offset (&iter);
   if (gtk_text_iter_toggles_tag (&iter, tag) ||
       gtk_text_iter_backward_to_tag_toggle (&iter, tag))
@@ -321,13 +351,27 @@ check_specific_tag (GtkTextBuffer *buffer,
           else
             g_error ("backward_to_tag_toggle went to a location without a toggle");
         }
-      while (gtk_text_iter_backward_to_tag_toggle (&iter, tag));
+      while (gtk_text_iter_backward_to_tag_toggle (&iter, tag) &&
+             gtk_text_iter_compare (&iter, start) >= 0);
     }
 
   if (count != buffer_count)
-    g_error ("Counted %d tags iterating by char, %d iterating by tag toggle\n",
+    g_error ("Counted %d tags iterating by char, %d iterating backward by tag toggle\n",
              buffer_count, count);
+}
+
+static void
+check_specific_tag (GtkTextBuffer *buffer,
+                    const gchar   *tag_name)
+{
+  GtkTextIter start, end;
 
+  gtk_text_buffer_get_bounds (buffer, &start, &end);
+  check_specific_tag_in_range (buffer, tag_name, &start, &end);
+  gtk_text_iter_forward_chars (&start, 2);
+  gtk_text_iter_backward_chars (&end, 2);
+  if (gtk_text_iter_compare (&start, &end) < 0)
+    check_specific_tag_in_range (buffer, tag_name, &start, &end);
 }
 
 static void